package com.cabrida.livestar.model;

import java.io.IOException;

import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParserException;

/**
 * 数据操作结果实体类
 * @author swq
 * @version 1.0
 * @created 2012-3-21
 */
public class FieldFile extends Base {

	private static final long serialVersionUID = 534547191986166448L;
	private int errorCode;
	private String errorMessage;
	private String filePath;

	public boolean OK() {
		return errorCode == 1;
	}

	/**
	 * 解析调用结果
	 * 
	 * @param stream
	 * @return
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public static FieldFile parse(String string) throws IOException {
		FieldFile res = null;
		// 获得XmlPullParser解析器
		//XmlPullParser xmlParser = Xml.newPullParser();		
		
			try {
				
				res = new FieldFile();
				
				JSONObject obj = new JSONObject(string);				
				res.errorCode = obj.optInt("status_code");
				
				if(1 == res.errorCode){
					JSONObject data = obj.optJSONObject("return_data");
					res.filePath = data.optString("fi");
				}				
		} catch (Exception e) {
			
		}
		
		return res;

	}

	public int getErrorCode() {
		return errorCode;
	}
	public String getErrorMessage() {
		return errorMessage;
	}
	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	
	@Override
	public String toString(){
		return String.format("RESULT: CODE:%d,MSG:%s", errorCode, errorMessage);
	}

}
